const path = require('path');
const webpack = require('webpack');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
    mode: 'production',
    entry: {
        import: [
            '@iro/wechat-adapter',
            path.resolve('./', 'src/main.ts'),
        ],
    },
    output: {
        path: path.resolve('./', 'dist'),
        filename: 'main.js',
        library: 'WXMiniGameTs',
        libraryTarget: 'umd',
        libraryExport: 'default',
        globalObject: 'GameGlobal',
    },
    optimization: {
        // splitChunks: {
        //     chunks: 'all',
        // },
    },
    externals: {
    },
    module: {
        rules: [{
            test: /(.ts)$/,
            use: {
                loader: 'ts-loader'
            }
        }, {
            test: /(.js)$/,
            use: [{
                loader: 'babel-loader',
            }]
        }, {
            test: /\.mjs$/,
            include: /node_modules/,
            type: "javascript/auto"
        }]
    },
    plugins: [
        new ProgressBarPlugin(),
        new UglifyJsPlugin({
            // 允许并发
            parallel: true,
            // 开启缓存
            cache: true,
            uglifyOptions: {
                compress: true,
            },
            extractComments: false
        }),
        new webpack.DefinePlugin({
            CLOUD_ENV:"dev"
        }),
    ],
    resolve: {
        extensions: ['.tsx', '.ts', '.js'],
    },
    node: {// 不加这个构建会报错 Can't resolve 'fs' in '/Users/aloudata/WeChatProjects/wx-minigame-ts/src/js/libs/live2d' 不知道会不会有影响
        fs: 'empty'
    },
    performance: {
        maxEntrypointSize: 10000000,
        maxAssetSize: 30000000
    }
};